home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr44 / modex32w.zip / FILLRECT.ASM < prev    next >
Assembly Source File  |  1995-02-21  |  5KB  |  127 lines

  1.         .386p
  2.         locals
  3.         include w.inc
  4.  
  5. ; Mode X (320x240, 256 colors) rectangle fill routine. Works on all
  6. ; VGAs. Uses fast approach that fans data out to up to four planes at
  7. ; once to draw up to four pixels at once. Fills up to but not
  8. ; including the column at EndX and the row at EndY. No clipping is
  9. ; performed.
  10. ; C near-callable as:
  11. ;    void FillRectangleX(int StartX, int StartY, int EndX, int EndY,
  12. ;       unsigned int PageBase, int Color);
  13. ;
  14. ; Modified Aug 30, 1994 (ykumanan)
  15. ; ) Made code 32 bit pm (not fully optimized)
  16. ;
  17.  
  18. SC_INDEX equ    03c4h   ;Sequence Controller Index
  19. MAP_MASK equ    02h     ;index in SC of Map Mask register
  20.  
  21. parms   struc
  22.         dd      2 dup (?) ;pushed EBP and return address
  23. StartX  dd      ?       ;X coordinate of upper left corner of rect
  24. StartY  dd      ?       ;Y coordinate of upper left corner of rect
  25. EndX    dd      ?       ;X coordinate of lower right corner of rect
  26.                         ; (the row at EndX is not filled)
  27. EndY    dd      ?       ;Y coordinate of lower right corner of rect
  28.                         ; (the column at EndY is not filled)
  29. PageBase dd     ?       ;base offset in display memory of page in
  30.                         ; which to fill rectangle
  31. Color   dd      ?       ;color in which to draw pixel
  32. parms   ends
  33.  
  34.         @dseg
  35.  
  36.         extrn   SCREEN_SEG:dword
  37.         extrn   SCREEN_WIDTH:dword      ;width of screen in bytes from
  38.                                         ; one scan line to the next
  39.         extrn   LeftClipPlaneMask:byte
  40.         extrn   RightClipPlaneMask:byte
  41.  
  42.         ends
  43.         @cseg
  44.  
  45.         public  _FillRectangleX
  46. _FillRectangleX proc    near
  47.         push    ebp     ;preserve caller's stack frame
  48.         mov     ebp,esp ;point to local stack frame
  49.         push    esi     ;preserve caller's register variables
  50.         push    edi
  51.         push    ebx
  52.  
  53.         cld
  54.         mov     eax, [SCREEN_WIDTH]
  55.         imul    eax, [ebp+StartY] ;offset in page of top rectangle scan line
  56.         mov     edi, [ebp+StartX]
  57.         shr     edi,2    ;X/4 = offset of first rectangle pixel in scan line
  58.         add     edi,eax   ;offset of first rectangle pixel in page
  59.         add     edi,[ebp+PageBase] ;offset of first rectangle pixel in
  60.                         ; display memory
  61.         add     edi, [SCREEN_SEG]       ; point es:edi to 1st rect
  62.         mov     dx,SC_INDEX ;set the Sequence Controller Index to
  63.         mov     al,MAP_MASK ; point to the Map Mask register
  64.         out     dx,al
  65.         inc     dx      ;point DX to the SC Data register
  66.         mov     esi,[ebp+StartX]        ; make hi(esi) zero
  67.         and     esi,0003h                 ;look up left edge plane mask
  68.         mov     bh,LeftClipPlaneMask[esi] ; to clip & put in BH
  69.         mov     esi,[ebp+EndX]
  70.         and     esi,0003h                  ;look up right edge plane
  71.         mov     bl,RightClipPlaneMask[esi] ; mask to clip & put in BL
  72.         
  73.         mov     ecx,[ebp+EndX]    ;calculate # of addresses across rect
  74.                                   ; make hi(ecx) zero
  75.         mov     esi,[ebp+StartX]
  76.         cmp     ecx,esi
  77.         jle     FillDone        ;skip if 0 or negative width
  78.         dec     ecx
  79.         and     esi,not 011b
  80.         sub     ecx,esi
  81.         shr     ecx,2    ;# of addresses across rectangle to fill - 1
  82.         jnz     MasksSet ;there's more than one byte to draw
  83.         and     bh,bl   ;there's only one byte, so combine the left
  84.                         ; and right edge clip masks
  85. MasksSet:
  86.         mov     esi,[ebp+EndY]
  87.         sub     esi,[ebp+StartY]  ;BX = height of rectangle
  88.         jle     FillDone        ;skip if 0 or negative height
  89.         mov     ah,byte ptr [ebp+Color] ;color with which to fill
  90.         mov     ebp, [SCREEN_WIDTH] ;stack frame isn't needed any more
  91.         sub     ebp,ecx   ;distance from end of one scan line to start
  92.         dec     ebp      ; of next
  93. FillRowsLoop:
  94.         push    ecx      ;remember width in addresses - 1
  95.         mov     al,bh   ;put left-edge clip mask in AL
  96.         out     dx,al   ;set the left-edge plane (clip) mask
  97.         mov     al,ah   ;put color in AL
  98.         stosb           ;draw the left edge
  99.         dec     ecx      ;count off left edge byte
  100.         js      FillLoopBottom ;that's the only byte
  101.         jz      DoRightEdge ;there are only two bytes
  102.         mov     al,00fh ;middle addresses are drawn 4 pixels at a pop
  103.         out     dx,al   ;set the middle pixel mask to no clip
  104.         mov     al,ah   ;put color in AL
  105.         rep     stosb   ;draw the middle addresses four pixels apiece
  106. DoRightEdge:
  107.         mov     al,bl   ;put right-edge clip mask in AL
  108.         out     dx,al   ;set the right-edge plane (clip) mask
  109.         mov     al,ah   ;put color in AL
  110.         stosb           ;draw the right edge
  111. FillLoopBottom:
  112.         add     edi,ebp ;point to the start of the next scan line of
  113.                         ; the rectangle
  114.         pop     ecx      ;retrieve width in addresses - 1
  115.         dec     esi      ;count down scan lines
  116.         jnz     FillRowsLoop
  117. FillDone:
  118.         pop     ebx
  119.         pop     edi     ;restore caller's register variables
  120.         pop     esi
  121.         pop     ebp     ;restore caller's stack frame
  122.         ret
  123. _FillRectangleX endp
  124.         ends
  125.         end
  126.  
  127.